package org.uni.cil.tester;

import java.io.IOException;
import java.text.DecimalFormat;
import java.util.logging.FileHandler;
import java.util.logging.Level;

import javax.servlet.jsp.JspWriter;

import org.uni.cil.ping.JavaPing;
import org.uni.cil.tester.TestCase;
import org.uni.cil.controller.*;


public class Tester {

 public static void main(JspWriter out, TestCase testCase) {
	 DecimalFormat timeFormat = new DecimalFormat("###.###");
	 String ip = testCase.crmProviderIp;
	try {
		double pingTime = JavaPing.getAveragePingTime(ip);
		out.write("<b>Ping " + ip + ":</b> AverageTime (5 pings):" + timeFormat.format(pingTime) + "ms");
	} catch (Exception e) {
		// TODO Auto-generated catch block
		try {
			out.write("Ping to " + ip + " failed!");
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	}
	
	ip = testCase.mailProviderIp;
	try {
		double pingTime = JavaPing.getAveragePingTime(ip);
		out.write("<br><b>Ping " + ip + "</b>: AverageTime (5 pings):" + timeFormat.format(pingTime) + "ms");
	} catch (Exception e) {
		// TODO Auto-generated catch block
		try {
			out.write("<br>Ping to " + ip + " failed!");
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	}
	 Controller ctrl1 = new Controller();
	 ctrl1.run(out, testCase.mailConnectionData, testCase.crm.name(), testCase.searchTokens, testCase.searchValues);
	 }
}
